package com.dnui.seven2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnui.seven2.common.R;
import com.dnui.seven2.entity.Employee;
import com.dnui.seven2.entity.Merch;
import com.dnui.seven2.entity.Performer;
import com.dnui.seven2.service.PerformerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/performer")
@Slf4j
public class PerformerController {
    @Autowired
    private PerformerService performerService;

    @GetMapping("/queryPerformers")
    public R<Page> queryPerformers( Integer currentPageNum,  Integer everyPage ){
        //构造分页构造器
        Page pageInfo=new Page(currentPageNum,everyPage);
        //构造条件构造器
        LambdaQueryWrapper<Performer> queryWrapper=new LambdaQueryWrapper();

        //执行查询
        performerService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    @PostMapping("/savePerformer")
    public R<String> savePerformer(@RequestBody Performer performer){
        performerService.save(performer);
        return  R.success("添加成功");
    }

    @PutMapping("updatePerformer")
    public R<String> updatePerformer(@RequestBody Performer performer){
        performerService.updatePerformer(performer);
        return  R.success("修改成功");
    }

    @DeleteMapping("deletePerformer/{performerId}")
    public R<String> deletePerformer(@PathVariable Long performerId){
        performerService.deletePerformer(performerId);
        return  R.success("删除成功");
    }

    @GetMapping("/getById/{performerId}")
    public R<Performer> getById(@PathVariable Long performerId){
        log.info("根据id查询员工信息");
        Performer performer=performerService.getById(performerId);
        return R.success(performer);
    }

    @GetMapping("/selectAll")
    public R<List<Performer>> selectAll(){
        List<Performer> performers = performerService.selectAll();
        return  R.success(performers);
    }
}
